﻿namespace TC
{
    public class IfElse_tree : TranslateTree
    {
        public override editor.cfg.behaviourtree.TreeNode OnTranslate(Node node)
        {
            IfElse t = node as IfElse;
            editor.cfg.behaviourtree.IfElse re = new editor.cfg.behaviourtree.IfElse();
            re.id = t.id;

            Port p = t.graph.GetConnect(t.flowT);
            if (p != null)
            {
                re.trueFlow = BTGraphExport.translate[p.parent.GetType()].OnTranslate(p.parent);
            }
            p = t.graph.GetConnect(t.flowF);
            if (p != null)
            {
                re.falseFlow = BTGraphExport.translate[p.parent.GetType()].OnTranslate(p.parent);
            }
            p = t.graph.GetConnect(t.condition);
            if (p == null)
            {
                throw new System.Exception("IfElse condition is null");
            }

            re.condition = new editor.cfg.blueprint.OutputPin() { nodeId = p.parent.id, pinName = p.name };
            return re;
        }
    }
}
